package com.rany.day07.demo02;

import java.util.ArrayList;
import java.util.Collection;

public class Iterator {
    public static void main(String[] args) {
        //多态
        Collection<String> c = new ArrayList<>();
        c.add("张三");
        c.add("李四");
        c.add("王五");
        //获取迭代器
        java.util.Iterator<String> iterator = c.iterator();
        //判断有误参数
        while (iterator.hasNext()){
            //获取元素并且指针指到下一个
            String next = iterator.next();
            System.out.println(next);
        }
    }
}
